<template>
  <a-layout-header :class="[headerTheme, 'admin-header']">
    <div :class="['admin-header-wide', layout, pageWidth]">
      <!--      <router-link v-if="isMobile || layout === 'head'" to="/" :class="['logo', isMobile ? null : 'pc', headerTheme]">-->
      <!--        <img width="32" src="@/assets/img/logo.png" />-->
      <!--        <h1 v-if="!isMobile">{{systemName}}</h1>-->
      <!--      </router-link>-->
      <div class="webLog theme" @click="goConsolePage">
          <img style="width: 25px; margin-right: 5px;" src="../../assets/img/logo-main.png"/>
          <span class="title">{{ systemName }}</span>
        <!-- <img src="@/assets/img/logo.png" /> -->
      </div>
      <a-divider v-if="isMobile" type="vertical" />
           <a-icon v-if="layout !== 'head'" class="trigger" :type="collapsed ? 'menu-unfold' : 'menu-fold'" @click="toggleCollapse"/>
      <div :class="['admin-header-right', headerTheme]">
        <!--          <header-notice class="header-item"/>-->
        <a-popover>
          <template slot="content">
            <span>用户须知</span>
          </template>
            <!-- <span style=" margin-right: 15px; font-size: 15px;" > <img src="../../assets/img/userNotice/notice.png" alt="" @click="notice"></span> -->
            <a-icon type="question-circle" @click="notice" style="margin-top: 19px;fontSize:22px"/>
        </a-popover>

        <header-avatar class="header-item" />
        <!--          国际化-->
        <!--          <a-dropdown class="lang header-item">-->
        <!--            <div>-->
        <!--              <a-icon type="global"/> {{langAlias}}-->
        <!--            </div>-->
        <!--            <a-menu @click="val => setLang(val.key)" :selected-keys="[lang]" slot="overlay">-->
        <!--              <a-menu-item v-for=" lang in langList" :key="lang.key">{{lang.key.toLowerCase() + ' ' + lang.name}}</a-menu-item>-->
        <!--            </a-menu>-->
        <!--          </a-dropdown>-->
      </div>
    </div>
    <user-notice ref="UserNotice" />
  </a-layout-header>
</template>

<script>
// import HeaderNotice from './HeaderNotice' //通知徽标
import HeaderAvatar from "./HeaderAvatar";
import UserNotice from './UserNotice'
import { mapState, mapMutations, mapGetters } from "vuex";
import {getStore} from "@/utils/store";

export default {
  name: "AdminHeader",
  components: { HeaderAvatar, UserNotice },
  props: ["collapsed", "menuData"],
  data() {
    return {
      langList: [
        { key: "CN", name: "简体中文", alias: "简体" },
        { key: "HK", name: "繁體中文", alias: "繁體" },
        { key: "US", name: "English", alias: "English" }
      ],
      searchActive: false,
      firstPath: ''
    };
  },
  created () {
    this.firstPath = getStore({name: 'firstMenuId_' + this.user['id']});
  },
  computed: {
    ...mapState("setting", [
      "theme",
      "isMobile",
      "layout",
      "systemName",
      "lang",
      "pageWidth"
    ]),
    ...mapGetters("account", ["user"]),
    headerTheme() {
      if (
        this.layout == "side" &&
        this.theme.mode == "dark" &&
        !this.isMobile
      ) {
        return "light";
      }
      return this.theme.mode;
    },
    langAlias() {
      let lang = this.langList.find(item => item.key == this.lang);
      return lang.alias;
    },
    menuWidth() {
      const { layout, searchActive } = this;
      const headWidth = layout === "head" ? "100% - 188px" : "100%";
      const extraWidth = searchActive ? "600px" : "400px";
      return `calc(${headWidth} - ${extraWidth})`;
    },
    systemName() {
      return this.$store.state.setting.systemName;
    }
  },
  methods: {
    toggleCollapse() {
      this.$emit("toggleCollapse");
    },
    onSelect(obj) {
      this.$emit("menuSelect", obj);
    },
    ...mapMutations("setting", ["setLang"]),
    goConsolePage() {
      if (this.$route.path == "/" + this.firstPath) {
        this.$router.go(0);
      } else {
        this.$router.push("/" + this.firstPath);
      }
    },
    notice(){
      this.$refs.UserNotice.show(true)
    }
  }
};
</script>

<style lang="less" scoped>
@import "index";
</style>
